package com.example.demo.Controller;

import com.example.demo.Entity.FSFolder;
import com.example.demo.Master.MasterBase;
import com.example.demo.Service.FileService;
import net.sf.json.JSONObject;;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/File")
public class FileController {

    @Autowired
    private FileService fileService;


    //上传文件（虚拟），待补充请求参数
    @RequestMapping("/uploadFSFile")
    public void uploadFSFile(String userName, String filePath, String type,long size,MasterBase masterBase){

        //返回服务器名称
        fileService.uploadFile(userName,filePath,type,size,masterBase);
    }

    //上传文件（实际）
    @RequestMapping("/updateTrueFile")
    //filePath包含文件名，不包括/root/用户名，path例如/qqq/www/eee/r.txt
    public void uploadTrueFile(String serverName,String filePath,String content,String userName,MasterBase masterbase){
        fileService.uploadTrueFile(serverName,filePath,content,userName,masterbase);
    }

    //文件在线查看
    @RequestMapping("/browseFiles")
    public void browseFiles(String userName,String filePath,MasterBase masterBase){
        String content = fileService.browseFiles(userName,filePath,masterBase);
    }

    //显示文件列表（List转json）
    @RequestMapping("/showList")
    public List showList(String userName,String folderPath,MasterBase masterBase){
          List list = fileService.showList(userName,folderPath,masterBase);
          return list;
    }

    //删除文件到回收站
    @RequestMapping("/deleteToRecycle")
    public void deleteToRecycle(String userName,String filePath,MasterBase masterBase){
        fileService.deleteToRecycle(userName,filePath,masterBase);
    }

    //重命名文件
    @RequestMapping("renameFile")
    public void renameFile(String userName,String filePath,MasterBase masterBase,String newName){
        fileService.renameFile(userName,filePath,masterBase,newName);
    }

}
